package J5_15;

import java.util.Scanner;

public class test {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        while (n -- > 0) {
            int num = in.nextInt();
            System.out.println(a(num));
        }
    }

    private static int a(int num) {
        if (num % 2 == 0) {
            return num;
        }
        String strNum = Integer.toString(num);
        int p = -1;
        for (int i = 0; i < strNum.length(); i++) {
            if ((strNum.charAt(i) - '0') % 2 == 0) {
                p = i;
                break;
            }
        }
        if (p != -1) {
            StringBuilder res = new StringBuilder(strNum);
            char ch = res.charAt(p);
            res.setCharAt(p, res.charAt(res.length() - 1));
            res.setCharAt(res.length() - 1, ch);
            return Integer.parseInt(new String(res));
        }
        return -1;
    }


    static int res , n;
    static boolean[] vis = new boolean[11];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        int[] arr = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
        }
        dfs(1, arr);
        System.out.println(res);
    }

    private static void dfs(int i,int[] arr) {
        if (i == n + 1) {
            res++;
            return;
        }
        for (int j = 1; j <= n; j++) {
            if (vis[j]) {
                continue;
            }
            if (vis[arr[j]]) {
                break;
            }
            vis[j] = true;
            dfs(j + 1, arr);
            vis[j] = false;
        }
    }

}
